package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.uni.service.IDcCustomerService;
import com.ruoyi.uni.domain.DcCustomer;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

/**
 * 客户管理Controller
 * 
 * @author hx
 * @date 2024-04-16
 */
@RestController
@RequestMapping("/system/customer")
public class DcCustomerController extends BaseController
{
    @Autowired
    private IDcCustomerService dcCustomerService;

    @PreAuthorize("@ss.hasPermi('system:customer:edit')")
    @GetMapping("status/{id}")
    public String updateStatus(@PathVariable("id") Long id){
        return dcCustomerService.updateStatus(id);
    }

    /**
     * 查询客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(DcCustomer dcCustomer)
    {
        startPage();
        List<DcCustomer> list = dcCustomerService.selectDcCustomerList(dcCustomer);
        return getDataTable(list);
    }

    /**
     * 导出客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:customer:export')")
    @Log(title = "客户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DcCustomer dcCustomer)
    {
        List<DcCustomer> list = dcCustomerService.selectDcCustomerList(dcCustomer);
        ExcelUtil<DcCustomer> util = new ExcelUtil<DcCustomer>(DcCustomer.class);
        util.exportExcel(response, list, "客户管理数据");
    }

    /**
     * 获取客户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:customer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dcCustomerService.selectDcCustomerById(id));
    }

    /**
     * 新增客户管理
     */
    @PreAuthorize("@ss.hasPermi('system:customer:add')")
    @Log(title = "客户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcCustomer dcCustomer)
    {
        return toAjax(dcCustomerService.insertDcCustomer(dcCustomer));
    }

    /**
     * 修改客户管理
     */
    @PreAuthorize("@ss.hasPermi('system:customer:edit')")
    @Log(title = "客户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DcCustomer dcCustomer)
    {
        return toAjax(dcCustomerService.updateDcCustomer(dcCustomer));
    }

    /**
     * 删除客户管理
     */
    @PreAuthorize("@ss.hasPermi('system:customer:remove')")
    @Log(title = "客户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dcCustomerService.deleteDcCustomerByIds(ids));
    }
}
